﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;

using Microsoft.Surface;
using Microsoft.Surface.Presentation;
using Microsoft.Surface.Presentation.Controls;


namespace eGrid_App
{
    public class BookmarkInfoTipMock
    {
        //ScatterLayer parentLayer = null;
        BookmarkPin ttp;

        #region mock objects
        // Mocks for the text blocks and sliders
        // Initializing them according to the default state of the UI
        string TT_Num, TT_SEV, SS_SEV_Value, TT_DES, TT_LOC;
        string EditButton_Content = "Edit";
        
        SolidColorBrush TT_SEV_Foreground;
        SolidColorBrush EditButton_Background = new SolidColorBrush(Colors.Aqua);
        SolidColorBrush CloseButton_Background = new SolidColorBrush(Colors.White);

        Visibility this_Visibility = Visibility.Visible;
        Visibility ShowMapButton_Visibility = Visibility.Visible;
        Visibility SS_SEV_Visibility = Visibility.Collapsed;        
        
        bool TT_DES_IsEnabled = false;
        bool CloseButton_IsEnabled = true;

        #endregion

        #region constructors
        public BookmarkInfoTipMock(ScatterLayer parent, BookmarkPin pin)
        {
            //parentLayer = parent;

            ttp = pin;
            TT_Num = pin.Bookmark.ID;
            TT_SEV = pin.Bookmark.getBookmarkPriorityString();

            /* Change the background color of the Priority text accordingly */
            switch (TT_SEV)
            {
                case "High":
                    TT_SEV_Foreground = new SolidColorBrush(Colors.Red);
                    SS_SEV_Value = "1";
                    break;
                case "Medium":
                    TT_SEV_Foreground = new SolidColorBrush(Colors.Yellow);
                    SS_SEV_Value = "2";
                    break;
                case "Low":
                    TT_SEV_Foreground = new SolidColorBrush(Colors.Green);
                    SS_SEV_Value = "3";
                    break;
                default:
                    TT_SEV_Foreground = new SolidColorBrush(Colors.Gray);
                    break;
            }

            TT_DES = pin.Description;
            TT_LOC = pin.Bookmark.MapCoordinate.ToString();

            ShowMapButton_Visibility = Visibility.Visible;
        }

        public BookmarkInfoTipMock(BookmarkPin pin)
        {
            ttp = pin;
            TT_Num = pin.Bookmark.ID;
            TT_SEV = pin.Bookmark.getBookmarkPriorityString();
            TT_DES = pin.Description;
            TT_LOC = pin.Bookmark.MapCoordinate.ToString();
        }

        #endregion

        #region get functions for mock objects 
        //to be used in unit tests
        
        public BookmarkPin getBookmarkPin()
        {
            return ttp;
        }

        public string Get_TT_Num() { return TT_Num; }
        public string Get_TT_SEV() { return TT_SEV; }
        public string Get_SS_SEV_Value() { return SS_SEV_Value; }
        public string Get_TT_DES() { return TT_DES; }
        public string Get_TT_LOC() { return TT_LOC; }
        public string Get_EditButton_Content() { return EditButton_Content; }

        public SolidColorBrush Get_TT_SEV_Foreground() { return TT_SEV_Foreground; }
        public SolidColorBrush Get_EditButton_Background() { return EditButton_Background; }
        public SolidColorBrush Get_CloseButton_Background() { return CloseButton_Background; }

        public Visibility Get_this_Visibility() { return this_Visibility; }
        public Visibility Get_ShowMapButton_Visibility() { return ShowMapButton_Visibility; }
        public Visibility Get_SS_SEV_Visibility() { return SS_SEV_Visibility; }

        public bool Is_TT_DES_IsEnabled() { return TT_DES_IsEnabled; }
        public bool Is_CloseButton_IsEnabled() { return CloseButton_IsEnabled; }

        #endregion


        #region utility functions

        private void SwitchToEditMode()
        {
            TT_DES_IsEnabled = true;
            SS_SEV_Visibility = Visibility.Visible;
            EditButton_Background = new SolidColorBrush(Colors.Red);
            EditButton_Content = "Done Edit";
            /* Cannot exit when editing */
            CloseButton_IsEnabled = false;
            CloseButton_Background = new SolidColorBrush(Colors.Gray);            
        }

        private void SwitchToViewMode()
        {
            TT_DES_IsEnabled = false;
            SS_SEV_Visibility = Visibility.Collapsed;
            EditButton_Background = new SolidColorBrush(Colors.Aqua);
            EditButton_Content = "Edit";
            /* Re-enable the close button to allow the user to close the MapTip */
            CloseButton_IsEnabled = true;
            CloseButton_Background = new SolidColorBrush(Colors.White);
            /* Update the trouble ticket */
            ttp.Bookmark.Description = TT_DES;            
        }

        private void OpenMapFrame()
        {
            this_Visibility = Visibility.Hidden;

            //if (parentLayer == null) return;

            // FIX ME: the orientation and position of the map frame
            //parentLayer.CreateMapFrameFromBookmarkPin(ttp.Bookmark, Center, Orientation);
        }

        private void HideWindow()
        {
            this_Visibility = Visibility.Hidden;
        }

        private void ChangePriority(int newValue)
        {
            switch (newValue)
            {
                case 1:
                    TT_SEV_Foreground = new SolidColorBrush(Colors.Red);
                    TT_SEV = "High";
                    ttp.Priority = Bookmark.BookmarkPriority.High;
                    break;
                case 2:
                    TT_SEV_Foreground = new SolidColorBrush(Colors.Yellow);
                    TT_SEV = "Medium";
                    ttp.Priority = Bookmark.BookmarkPriority.Medium;
                    break;
                case 3:
                    TT_SEV_Foreground = new SolidColorBrush(Colors.Green);
                    TT_SEV = "Low";
                    ttp.Priority = Bookmark.BookmarkPriority.Low;
                    break;
                default:
                    TT_SEV_Foreground = new SolidColorBrush(Colors.Gray);
                    TT_SEV = "N/A";
                    break;
            }
        }

        #endregion

    }
}
